package com.ruoyi.common.utils;

import com.alibaba.fastjson2.JSONObject;
import okhttp3.*;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

public class POSTUtil {

    public static Map sendMrInData(String msgBody, String msgType){
            Map map = new HashMap();
            String json2 = null;
            System.out.println("推送数据线程开始执行");
            String msg = "<message>\n" +
                    "<msg_type>"+ msgType +"</msg_type>\n" +
                    "<msg_sender>49455020-4</msg_sender>\n" +
                    "<msg_orgsn>101</msg_orgsn>\n" +
                    "<msg_time>"+ System.currentTimeMillis() +"</msg_time>\n" +
                    "<msg_sign>481</msg_sign>\n" +
                    "<msg_body>"+ msgBody +"</msg_body>\n" +
                    "</message>";
            OkHttpClient client = new OkHttpClient().newBuilder().build();
            MediaType mediaType = MediaType.parse("application/xml");
            RequestBody body = RequestBody.create(mediaType,msg);//.create(mediaType,json.toString());//create(mediaType, json);
            Request request = new Request.Builder()
                    .url("http://11.0.0.132:7003/tda_accept/acceptXML/mrInterface")
                    .method("POST", body)
                    .addHeader("Content-Type", "application/xml")
                    .build();
            try {
                Response response = client.newCall(request).execute();
                json2 = response.body().string();
                System.out.println("--------入参--------");
                System.out.println(msg);
                System.out.println("--------返回值--------");
                System.out.println(json2);
            } catch (IOException e) {
                e.printStackTrace();
            }
            System.out.println("推送数据执行结束");
            map.put("json", json2);
            map.put("msg", msg);
        return map;
    }
}
